package com.yanqu.road.server.cmd.scene;

import com.yanqu.road.entity.scene.UserScene;
import com.yanqu.road.logic.pb.ScenePb;
import com.yanqu.road.pb.scene.SceneProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.scene.SceneMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_SCENE_UPDATE, desc = "跨服通知本服更新场景")
public class UpdateSceneFromCrossCmd extends AbstractCommand {

    private UserScene userScene;
    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SceneProto.UpdateSceneFromCrossReqMsg reqMsg = SceneProto.UpdateSceneFromCrossReqMsg.parseFrom(packet.getBytes());
        userScene = ScenePb.parseUserScene(reqMsg.getSceneMsg());
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (type == 1) {
            SceneMgr.enterScene(userScene, false);
        } else if (type == 2) {
            SceneMgr.quitScene(userScene.getUserId(), userScene.getUpdateTime(), false);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
